﻿using System;
using DMS.BaseClass;
using DMS.Business.Modules.Organization;
using DMS.Business.Utility;

namespace DMS.Business.Modules.SupplierManagement
{
    /// <summary>
    /// 合同信息
    /// </summary>
    public class ContractInfo
    {
        #region 数据成员
        private string _contractID = "";
        private string _supplierID = "";
        private string _supplierName = string.Empty;
        private string _projectID = "";
        private string _projectName = string.Empty;
        private string _contractNo = string.Empty;
        private double _contractMoney = 0;
        private double _closedMoney = 0;
        private string _contractName = string.Empty;
        private DateTime _startDate = DateTime.MinValue;
        private DateTime _endDate = DateTime.MinValue;
        private string _creatorID = "";
        private string _creatorName = string.Empty;
        private DateTime _createTime = DateTime.MinValue;
        private User _creator = null;
        private StatusType _status = StatusType.Actived;
        #endregion

        #region 成员属性
        /// <summary>
        /// 合同信息唯一编码
        /// </summary>
        public string ContractID
        {
            get
            {
                return this._contractID;
            }
            set
            {
                this._contractID = value;
            }
        }
        public string SupplierID
        {
            get
            {
                return this._supplierID;
            }
            set
            {
                this._supplierID = value;
            }
        }
        public string SupplierName
        {
            get
            {
                return this._supplierName;
            }
            set
            {
                this._supplierName = value;
            }
        }
        public string ProjectID
        {
            get
            {
                return this._projectID;
            }
            set
            {
                this._projectID = value;
            }
        }
        public string ProjectName
        {
            get
            {
                return this._projectName;
            }
            set
            {
                this._projectName = value;
            }
        }
        public string ContractNo
        {
            get
            {
                return this._contractNo;
            }
            set
            {
                this._contractNo = value;
            }
        }
        public string ContractName
        {
            get
            {
                return this._contractName;
            }
            set
            {
                this._contractName = value;
            }
        }
        public double ContractMoney
        {
            get
            {
                return this._contractMoney;
            }
            set
            {
                this._contractMoney = value;
            }
        }
        public double ClosedMoney
        {
            get
            {
                return this._closedMoney;
            }
            set
            {
                this._closedMoney = value;
            }
        }
        public DateTime StartDate
        {
            get
            {
                return this._startDate;
            }
            set
            {
                this._startDate = value;
            }
        }
        public DateTime EndDate
        {
            get
            {
                return this._endDate;
            }
            set
            {
                this._endDate = value;
            }
        }
        /// <summary>
        /// 创建人ID
        /// </summary>
        public string CreatorID
        {
            get
            {
                return this._creatorID;
            }
            set
            {
                this._creatorID = value;
            }
        }
        /// <summary>
        /// 创建人姓名
        /// </summary>
        public string CreatorName
        {
            get
            {
                return this._creatorName;
            }
            set
            {
                this._creatorName = value;
            }
        }
        /// <summary>
        /// 创建人
        /// </summary>
        public User Creator
        {
            get
            {
                if (this._creator == null && this._creatorID != "")
                {
                    this._creator = UserHelper.GetUserByID(this._creatorID);
                }
                return this._creator;
            }
            set
            {
                this._creator = value;

                if (value != null)
                {
                    this._creatorID = value.ID;
                    this._creatorName = value.Name;
                }
                else
                {
                    this._creatorID = "";
                    this._creatorName = string.Empty;
                }
            }
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime
        {
            get
            {
                return this._createTime;
            }
            internal set
            {
                this._createTime = value;
            }
        }
        /// <summary>
        /// 状态
        /// </summary>
        public StatusType Status
        {
            get
            {
                return this._status;
            }
            set
            {
                this._status = value;
            }
        }
        #endregion

        #region 构造函数
        public ContractInfo()
        {
        }
        public ContractInfo(string contractID)
        {
            this._contractID = contractID;
        }
        #endregion

        #region 成员方法

        /// <summary>
        /// 保存
        /// </summary>
        public void Save()
        {
            if (this._contractID == "")
            {
                User user = SystemContext.Current.LoginUser;
                this._contractID = Guid.NewGuid().ToString();
                this._creatorName = user.Name;
                this._creatorID = user.ID;
                this._createTime = DateTime.Now;

                ContractHelper.AddContractInfo(this);
            }
            else
            {
                ContractHelper.UpdateContractInfo(this);
            }
        }

        #endregion
    }
}
